//
//  ItemCell.m
//  Rss
//
//  Created by Wang Shuguang on 12-5-10.
//  Copyright 2012 Dawn. All rights reserved.
//

#import "ItemCell.h"
#import "PublicMethods.h"

@implementation ItemCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
		//背景
		UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
		UIImage *bgImage = [UIImage noCacheImageNamed:@"headview_cell_background.png"];
		bgImageView.image = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width / 2   topCapHeight:bgImage.size.height / 2];
		self.backgroundView = bgImageView;
		[bgImageView release];
		
		//选中背景
		UIImageView *selectedBgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
		bgImage = [UIImage noCacheImageNamed:@"headview_cell_background_selected.png"];
		selectedBgImageView.image = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width / 2   topCapHeight:bgImage.size.height / 2];
		self.selectedBackgroundView = selectedBgImageView;
		[selectedBgImageView release];
		
		//状态标记图标
		flagImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 8, 8)];
		flagImageView.image = [UIImage noCacheImageNamed:@"cell_left_unread.png"];
		[self addSubview:flagImageView];
		[flagImageView release];
	
		
		//right arraw
		arrawImageView = [[UIImageView alloc] initWithFrame:CGRectMake(302, 0, 18, 12)];
		arrawImageView.image = [UIImage noCacheImageNamed:@"cell_right_arraw.png"];
		[self addSubview:arrawImageView];
		[arrawImageView release];
		arrawImageView.center =  CGPointMake(arrawImageView.center.x, 70.0f/2);
				
		//title
		titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(24, 5, 270, 16)];
		titleLabel.font = [UIFont boldSystemFontOfSize:16.0f];
		titleLabel.backgroundColor = [UIColor clearColor];
		titleLabel.textColor = [UIColor colorWithRed:70.0f/255.0f green:70.0f/255.0f blue:70.0f/255.0f alpha:1];
		titleLabel.highlightedTextColor = [UIColor whiteColor];
		[self addSubview:titleLabel];
		[titleLabel release];
		
		//description
		descLabel = [[UILabel alloc] initWithFrame:CGRectMake(24, 24, 270, 30)];
		descLabel.highlightedTextColor = [UIColor whiteColor];
		descLabel.textColor = [UIColor colorWithRed:154.0/255.0 green:154.0/255.0 blue:154.0/255.0 alpha:1];
		descLabel.backgroundColor = [UIColor clearColor];
		//descLabel.lineBreakMode = UILineBreakModeWordWrap;
		descLabel.numberOfLines = 2;
		descLabel.font = [UIFont systemFontOfSize:12.0f];
		[self addSubview:descLabel];
		[descLabel release];
		
		//pubdate
		pubDateLable = [[UILabel alloc] initWithFrame:CGRectMake(24, 54, 270, 14)];
		pubDateLable.highlightedTextColor = [UIColor whiteColor];
		pubDateLable.textColor = [UIColor colorWithRed:154.0/255.0 green:154.0/255.0 blue:154.0/255.0 alpha:1];
		pubDateLable.backgroundColor = [UIColor clearColor];
		pubDateLable.font = [UIFont systemFontOfSize:12.0f];
		pubDateLable.textAlignment = UITextAlignmentRight;
		[self addSubview:pubDateLable];
		[pubDateLable release];
		
		
    }
    return self;
}

-(void) setTitle:(NSString *)title{
	titleLabel.text = title;
}

-(void) setDesc:(NSString *)desc{
	//CGSize descSize = [desc sizeWithFont:[UIFont boldSystemFontOfSize:12.0f] constrainedToSize:CGSizeMake(descLabel.frame.size.width, 30000) lineBreakMode:UILineBreakModeWordWrap];
//	descSize = CGSizeMake(descSize.width, descSize.height + 20); 
//	descLabel.frame = CGRectMake(descLabel.frame.origin.x, descLabel.frame.origin.y, descLabel.frame.size.width, descSize.height);
	descLabel.text = desc;
}

-(void) setPubDate:(NSString *)pubDate{
	pubDateLable.text = [PublicMethods dateSwitchFromDateString:pubDate];
}

-(void) setReaded:(BOOL)readed{
	if (readed) {
		flagImageView.hidden = YES;
		arrawImageView.image = [UIImage imageNamed:@"cell_right_arraw_cache.png"];
		titleLabel.textColor = [UIColor colorWithRed:154.0/255.0 green:154.0/255.0 blue:154.0/255.0 alpha:1];
	}else {
		flagImageView.hidden = NO;
		arrawImageView.image = [UIImage imageNamed:@"cell_right_arraw.png"];
		titleLabel.textColor = [UIColor colorWithRed:70.0f/255.0f green:70.0f/255.0f blue:70.0f/255.0f alpha:1];
	}

}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    
    if (highlighted) {
		flagImageView.image = [UIImage noCacheImageNamed:@"cell_left_unread_highlight.png"];
		arrawImageView.image = [UIImage noCacheImageNamed:@"cell_right_arraw_highlight.png"];
		titleLabel.highlighted = YES;
		descLabel.highlighted = YES;
		pubDateLable.highlighted = YES;
    }else {
		flagImageView.image = [UIImage noCacheImageNamed:@"cell_left_unread.png"];
		arrawImageView.image = [UIImage noCacheImageNamed:@"cell_right_arraw.png"];
		titleLabel.highlighted = NO;
		descLabel.highlighted = NO;
		pubDateLable.highlighted = NO;
	}

}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
	[super setSelected:selected animated:animated];
	
	if (selected) {
		flagImageView.image = [UIImage noCacheImageNamed:@"cell_left_unread_highlight.png"];
		arrawImageView.image = [UIImage noCacheImageNamed:@"cell_right_arraw_highlight.png"];
		titleLabel.highlighted = YES;
		descLabel.highlighted = YES;
		pubDateLable.highlighted = YES;
    }else {
		flagImageView.image = [UIImage noCacheImageNamed:@"cell_left_unread.png"];
		arrawImageView.image = [UIImage noCacheImageNamed:@"cell_right_arraw.png"];
		titleLabel.highlighted = NO;
		descLabel.highlighted = NO;
		pubDateLable.highlighted = NO;
	}
	

}


- (void)dealloc {
    [super dealloc];
}


@end
